package com.cloudpivot.receivales.crm.service;


import com.cloudpivot.receivales.crm.entity.weekly.WeeklyCount;
import com.cloudpivot.receivales.crm.repository.weekly.WeeklyCountRepository;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 周报统计 接口
 */
@Service
@Slf4j
public class WeeklyCountServiceImpl {
    @Autowired
    private WeeklyCountRepository weeklyCountRepository;

    @Autowired
    private ObjectMapper objectMapper;

    public List<WeeklyCount> getList(String businessUnitId, String startTime, String endTime) {

        List<WeeklyCount> weeklyCounts = weeklyCountRepository.getLists(businessUnitId,startTime,endTime);
        log.info("记录数：{}", weeklyCounts.size());
        try {
            log.info("返回的结果：{}", objectMapper.writeValueAsString(weeklyCounts));
            return weeklyCounts;
        } catch (JsonProcessingException e) {
            e.printStackTrace();
            return null;
        }
    }
}
